package com.study.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class NioClient {

    public static void main(String[] args) throws  Exception {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localost",7000));
        String filename = "d:/xx.zip";

        FileChannel fileChannel = new FileInputStream(filename).getChannel();

        long start = System.currentTimeMillis();
        // linux transferTo方法可以传输完成
        // window 一次调用transferTo只能发送8m,需要分段传输文件
        // transferTo 底层使用零拷贝
        long count = fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        System.out.println("发送总的字节数:"+count);

    }

}
